﻿using AnesSystem.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem
{
    public class RadioButtonHelper
    {
        #region Variables

        private List<CustomRadioButtonCtrl> list = new List<CustomRadioButtonCtrl>();


        #endregion


        #region Constructor
        public RadioButtonHelper()
        {

        }
        #endregion


        #region Properties


        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods


        #endregion


        #region Public/ProtectedMethods

        public void ChangeRadioSatus(params CustomRadioButtonCtrl[] radioButtons)
        {
            list = radioButtons.ToList();
            foreach (var item in list)
            {
                item.ValueChanged += Item_ValueChanged;
            }
        }
        private void Item_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                CustomRadioButtonCtrl radioButton = sender as CustomRadioButtonCtrl;
                if (radioButton.Value.GetType()==typeof(bool))
                {
                    if ((bool)radioButton.Value)
                    {
                        foreach (var item in list)
                        {
                            if (item.DisplayText.Equals(radioButton.DisplayText))
                            {
                                continue;
                            }
                            else
                            {
                                item.Value = false;
                            }
                        }
                    }
                    else
                    {
                        radioButton.Value = false;
                    }
                }
                if (radioButton.Value.GetType() == typeof(string))
                {
                    if (radioButton.Value.ToString().Equals("True"))
                    {
                        foreach (var item in list)
                        {
                            if (item.DisplayText.Equals(radioButton.DisplayText))
                            {
                                continue;
                            }
                            else
                            {
                                item.Value = "False";
                            }
                        }
                    }
                    else
                    {
                        radioButton.Value = "False";
                    }
                }

            }
            catch (Exception ex)
            {

                Common.LogHelper.Error(this.GetType(), ex);
            }
        }

        #endregion


        #region EventHandlers


        #endregion
    }
}
